<?php

class RequirementFaultsController extends AppController {

    var $name = 'RequirementFaults';

    function index($id=null) {

        $requerimientos = $this->RequirementFault->find('all', array(
            'recursive'=>-1,
                    'conditions' => array('RequirementFault.requirement_id' => $id),
            'fields'=>array('RequirementFault.nombre','RequirementFault.tipo','RequirementFault.id')
                ));
        $this->set('req', $requerimientos);
        $this->set('id', $id);
    }

    function add($id=null) {
        if (empty($this->data)) {
            $this->data['RequirementFault']['requirement_id'] = $id;
        } else {
            if ($this->RequirementFault->save($this->data)) {
                $ide = $this->data['RequirementFault']['requirement_id'];
                $this->setAction("index", $ide);
                $this->Session->setFlash('Restriccion adicionada');
            } else {
                
            }
        }
    }

    function delete($id, $req) {
        if ($this->RequirementFault->del($id)) {
            $this->setAction("index", $req);
            $this->Session->setFlash('Restricción eliminada  con exito');
        }
    }

    function edit($id=null) {

        if (empty($this->data)) {
            
            $this->data = $this->RequirementFault->find("first", array('recursive'=>-1,"conditions" => array("RequirementFault.id" => $id)));
        } else {
            if ($this->RequirementFault->save($this->data)) {
                $this->Session->setFlash('Restriccion editada con exito');
                $ide = $this->data['RequirementFault']['requirement_id'];
                $this->setAction("index", $ide);
            }
        }
    }

}

?>
